<template>
  <div class="app-container">
    <!-- *************************************搜索区************************************* -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <!--<el-form-item :label="$t('时间选择')">
        <!~~ 时间选择 ~~>
        <el-date-picker
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          v-model="queryParams.createTime"
          type="date"
          clearable
        />
      </el-form-item>-->

      <el-form-item :label="$t('审核状态')">
        <el-select clearable v-model="queryParams.status">
          <!-- 1.未审核
            2.已审核
            3.驳回 -->
          <el-option :label="$t('未审核')" :value="1" />
          <el-option :label="$t('已审核')" :value="2" />
          <el-option label="驳回" :value="3" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >
          {{ $t("搜索") }}
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">
          {{ $t("重置") }}
        </el-button>
      </el-form-item>
    </el-form>
    <el-row style="margin-bottom: 10px">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
    </el-row>
    <el-table
      :height="calTableHeight()"
      v-loading="loading"
        ref="TableRef"  :data="tableData"
      row-key="menuId"
    >
      <!-- 商家名称 商家地址 商家电话 邮箱 推荐人 审批状态 操作 -->
      <!-- 商家名称 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="merchantName"
        :label="$t('商家名称')"
      />
      <!-- 商家地址 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="merchantAddress"
        label="商家地址"
      />
      <!-- 商家电话 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="merchantTel"
        label="商家电话"
      />
      <!-- 邮箱 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="email"
        label="邮箱"
      />
      <!-- 推荐人 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="referrerName"
        label="推荐人"
      />
      <!-- 审批状态 -->
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="status"
        :label="$t('审批状态')"
      >
        <!-- 审核状态 1-待审批 2-审批通过 3-审批拒绝 -->
        <template slot-scope="{ row }">
          <span v-if="row.status == 1" style="color: red; cursor: pointer">
            待审批
          </span>
          <span v-if="row.status == 2" style="color: green; cursor: pointer">
            审批通过
          </span>
          <span v-if="row.status == 3" style="color: red; cursor: pointer">
            审批拒绝
          </span>
        </template>
      </el-table-column>

      <!-- 操作 -->
      <el-table-column
        align="center"
        fixed="right"
        :label="$t('操作')"
        :width="calWidth(200, 250, 200)"
      >
        <template slot-scope="{ row }">
          <!-- v-hasPermi="['distribution:stockCheck:updateStockCheckRemark']" -->
          <!-- 审核状态 1-待审批 2-审批通过 3-审批拒绝 -->
          <el-button
            v-show="row.status == 1"
            @click="handleAudit(row)"
            type="text"
            size="small"
          >
            <!-- 审核 -->
            审核
          </el-button>
          <el-button
            :disabled="row.status !== 1"
            type="text"
            size="small"
            @click="handleEdit(row)"
          >
            <!-- 修改信息 -->
            修改信息
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="pageTotal > 0"
      :total="pageTotal"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 审核 -->
    <AuditAndEdit
      :show.sync="auditAndEdit.show"
      @getList="getList"
      :formData="auditAndEdit.formData"
      :type="auditAndEdit.type"
    />
  </div>
</template>

<script>
import { list } from "@/api/platform/recommenSellerAudit";
import AuditAndEdit from "./auditAndEdit.vue";
export default {
  activated() {
    this.$nextTick(() => this.$refs['TableRef']?.doLayout())
  },
  name: "RecommenSellerAudit",
  components: {
    AuditAndEdit,
  },
  data() {
    return {
      showSearch: false,
      /**审核 & 修改*/
      auditAndEdit: {
        show: false,
        type: "",
        formData: {},
      },

      form: {},
      tableCheck: [],
      tableData: [],
      /**数据总条数 */
      pageTotal: 0,
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  async created() {
    this.getList();
  },

  methods: {
    handleAudit(row) {
      this.auditAndEdit.show = true;
      this.auditAndEdit.type = "audit";
      this.auditAndEdit.formData = JSON.parse(JSON.stringify(row));
    },
    handleEdit(row) {
      this.auditAndEdit.show = true;
      this.auditAndEdit.type = "edit";
      this.auditAndEdit.formData = JSON.parse(JSON.stringify(row));
    },
    // 取消申请
    cancel() {},
    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then((res) => {
        console.log(` ==>`, JSON.parse(JSON.stringify(res)));
        this.tableData = res.rows;
        this.pageTotal = res.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.value1 = null;
      Object.keys(this.queryParams).forEach((key) => {
        this.queryParams[key] = null;
      });
      this.queryParams.pageNum = 1;
      this.queryParams.pageSize = 10;

      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped></style>
